<template>
  <page-meta>
    <navigation-bar
      title="消息"
      title-align="center"
      background-color="#5896f5"
    />
  </page-meta>
  <view>
    <uni-list v-if="$store.state.user.userInfo != null">
      <uni-list-chat
        v-for="item in $store.state.message.messageList"
        :key="item.id"
        :title="item.title"
        :avatar="item.avatar"
        :note="item.note"
        :time="dateFormat(item.time)"
      />
    </uni-list>
  </view>
</template>

<script>
import { formatDate } from '@/common/util.js'
export default {
  data() {
    return {
      isShow: false
    }
  },
  onShow() {
    // 检查登录
    if (this.$ckeckLogin()) {
      this.isShow = true
      uni.hideTabBarRedDot({
        index: 2
      })
    }
  },
  updated() {
    // 如果当前正在这个界面 则不显示红点
    if (this.isShow) {
      uni.hideTabBarRedDot({
        index: 2
      })
    }
  },
  onHide() {
    this.isShow = false
  },
  mounted() {
    console.log('mounted')
  },
  methods: {
    dateFormat(datetime) {
      return formatDate(datetime * 1000)
    }
  }
}
</script>

<style>

</style>
